//package com.bjb.vr.remote.aop;
//
//import com.bjb.vr.common.ao.UmsAccountAo;
//import com.bjb.vr.common.constant.ThreadLocalConstant;
//import com.bjb.vr.common.constant.TokenConstants;
//import com.bjb.vr.common.exception.CommonException;
//import com.bjb.vr.common.result.BaseErrorCode;
//import com.bjb.vr.common.result.CommonResult;
//import com.bjb.vr.common.service.UmsAccountService;
//import com.bjb.vr.common.utils.ThreadLocalUtil;
//import com.bjb.vr.common.vo.UmsAccountVo;
//import com.bjb.vr.remote.utils.AccessRequestUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//import java.util.Objects;
//
///**
// * 请求信息拦截器--这样不用在每个请求方法上都校验一遍请求头中的token，提取出来
// *
// * @version 1.0.0
// * @author: HuJingBo
// * @time: 2022/4/18 11:37
// */
//@Slf4j
//@Aspect
//@Component
//public class UserAccoutInfoAspect {
//    @Autowired
//    private UmsAccountService accountService;
//
//    @Pointcut(value = "execution(* com.bjb.vr.remote.controller.*.*(..))")
//    public void checkUserPointcut() {
//    }
//
//    @Around(value = "checkUserPointcut()")
//    public Object around(ProceedingJoinPoint pjp) throws Throwable {
//        Map<String, String> headers = AccessRequestUtil.takeHeaders();
//        // 获取token
//        if (!headers.containsKey(TokenConstants.AUTHORIZATION.toLowerCase())) {
//            throw new CommonException("请求头中没有token");
//        }
//
//        // 查询用户信息
//        UmsAccountAo umsAccountAo = UmsAccountAo.builder().authorization(headers.get(TokenConstants.AUTHORIZATION.toLowerCase())).build();
//        UmsAccountVo accountInfo = accountService.getAccountInfo(umsAccountAo);
//        if (Objects.isNull(accountInfo)) {
//            return CommonResult.Fail(BaseErrorCode.ERROR_AUTHENTICATION);
//        }
//
//        Object resultObject = null;
//        try {
//            resultObject = pjp.proceed();
//        } catch (Exception ex) {
//            throw ex;
//        } finally {
//            // 清除线程变量
//            ThreadLocalUtil.remove(ThreadLocalConstant.USER_ACCOUNT_INFO);
//            ThreadLocalUtil.remove(ThreadLocalConstant.NO_TENANT_ID_VERIFY);
//        }
//        return resultObject;
//    }
//}
